|
|
|
| Table 9.3 ASCII Codes for Some Commonly Used Characters | | Code | Represents | | 8 | Backspace | | 9 | Tab | | 10 | Line feed | | 13 | Carriage return | | 32 | Space | | 34 | Double quotation mark (") | | 48 | 0 (the character for zero) | | 65 | A | | 97 | a |
|
|
|
|
|
|
Asc is the companion function to the Chr function. Asc returns the ASCII code of the input character. The following code shows how Asc is used: |
|
|
|
|
|
|
|
|
Print Asc("A") 'Returns 65 |
|
|
|
|
|
|
|
|
A string value can actually contain numeric digits, as you can see here: |
|
|
|
|
|
|
|
|
Dim sStringVal As String
Dim nNumber As Integer
nNumber = 99 'A number that can be used with math expressions
sStringVal = "16 candles" 'A string that cannot be used with math expressions |
|
|
|
|
|
|
|
|
You may already know that some numbers are often treated as character strings. Zip codes and phone numbers are two such examples. However, sometimes you need to convert a number to a string variable to use it in a string function or to print it in combination with another string. Likewise, you sometimes need to use numbers contained in a string variable in a mathematical equation or a numeric function. |
|
|
|
|
|
|
|
|
Visual Basic provides the Str function to convert a number to a string and the Val function to convert a string to a number. To convert a number to a string, you can do the following: |
|
|
|
|
|
|
|
|
numstr represents a string variable that contains the output of the function. inptnum represents the number to be converted. It can be a number, a numeric variable, or a numeric function. If inptnum is a positive number, Str returns a space in front of the number because Str reserves one character to contain a negative sign, if necessary. |
|
|
|
|
|
|
|
|
To convert a string to a number, you can use the Val function, as follows: |
|
|
|
|
|